package main

import (
	"fmt"
	"image"
	"image/color"
	_ "image/jpeg"
	_ "image/png"
	"learnGo/stock/imageUtil"
	"os"
)

func main() {

	fmt.Println(os.Getwd())
	f, err := os.Open("./stock/imageUtil/质检图.png")
	if err != nil {
		panic(err)
	}
	img, formatName, err := image.Decode(f)
	if err != nil {
		fmt.Println(err)
		panic(err)
	}
	f2, err := os.Open("./stock/imageUtil/差异图.png")
	if err != nil {
		panic(err)
	}
	img2, formatName2, err := image.Decode(f2)
	if err != nil {
		panic(err)
	}

	fmt.Println(formatName)
	fmt.Println(img.Bounds())
	fmt.Println(formatName2)
	fmt.Println(img2.Bounds())
	baseImg, err := imageUtil.GetImageFromNet("")
	if err != nil {
		return
	}
	fmt.Println(baseImg)
	maskImg, err := imageUtil.GetImageFromNet("")
	if err != nil {
		return
	}
	fmt.Println(maskImg)
	// 第一张图为质检图，第二张为差异图
	fontColor := color.RGBA{
		R: 45,
		G: 45,
		B: 45,
		A: 255,
	}
	imgg1 := ImageAddFont(img, "质检图", fontColor)
	imgg2 := ImageAddFont(img2, "差异图", fontColor)
	ww, _ := imageUtil.MergeImageNew(imgg1, imgg2)

	//images := WriteImages(args.Images, logics.GConfig.AliOss) //图片数据的处理

	err = imageUtil.SaveImage("./stock/res.png", ww)
	if err != nil {
		fmt.Println(err)
		return
	}
}

func ImageAddFont(img image.Image, content string, rgba color.RGBA) image.Image {
	imgSize := img.Bounds().Max
	imgWidth := imgSize.X
	imgHeight := imgSize.Y
	textBrush, err := imageUtil.NewTextBrush("./stock/imageUtil/pdffont.TTF", float64(imgWidth/20), image.Black, imgWidth/10)
	if err != nil {
		fmt.Println(err)
	}
	//
	//backgroud, err := imageUtil.GetImageFromFile("./img_1.png")
	//if err != nil {
	//	fmt.Println(err)
	//}
	des := imageUtil.Image2RGBA(img)
	//textBrush.DrawFontOnRGBA(des, image.Pt(10, 50), "世界你好")

	//调整颜色
	textBrush.FontColor = image.NewUniform(rgba)
	textBrush.DrawFontOnRGBA(des, image.Pt(imgWidth-imgWidth/5, imgHeight/8), content)
	return des

	//if err = imageUtil.SaveImage("./stock/text5.png", des); err != nil {
	//	fmt.Println(err)
	//}
}
